/**
 * 
 */
package Domain;
import java.util.HashSet;
import java.util.Set;

import java.util.Iterator;
/**
 * @author gth854p
 *
 */
public class DefinedClass implements RuleCommand {
	private String name;
	private Set<String> charSet;
	public DefinedClass()
	{
		setCharSet(new HashSet<String>());
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	void setCharSet(HashSet<String> charSet) {
		this.charSet = charSet;
	}
	Set<String> getCharSet() {
		return charSet;
	}
	@Override
	public boolean checkCorrectness(String compare) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean checkSyntax(String compare) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public NFADiagram createNFA() {
		System.out.println(this.name+"NFA");
		String temp;
		NFADiagram retval = new NFADiagram();
		NfaState start = new NfaState();
		NfaState end = new NfaState();
		retval.setNfaEnd(end);
		retval.setNfaStart(start);
		Iterator<String> iter = charSet.iterator();
		while(iter.hasNext())
		{
			temp = iter.next();
			if(temp.charAt(0)=='\\')
			{
				NfaState st1 = new NfaState();
				NfaState st2 = new NfaState();
				NfaState st3 = new NfaState();
				NfaState st4 = new NfaState();
				StateTransition s1 = new StateTransition(start,st1,(char)0);
				start.addTransition(s1);
				s1 = new StateTransition(st1,st2,'\\');
				st1.addTransition(s1);
				s1 = new StateTransition(st2,st3,(char)0);
				st2.addTransition(s1);
				s1 = new StateTransition(st3,st4,temp.charAt(1));
				st3.addTransition(s1);
				s1 = new StateTransition(st4,end,(char)0);
				st4.addTransition(s1);
			}
			else
			{
				NfaState st1 = new NfaState();
				NfaState st2 = new NfaState();
				StateTransition s1 = new StateTransition(start,st1,(char)0);
				start.addTransition(s1);
				s1 = new StateTransition(st1,st2,temp.charAt(0));
				st1.addTransition(s1);
				s1 = new StateTransition(st2,end,(char)0);
				st2.addTransition(s1);
			}
		}
		return retval;
	}
	@Override
	public Set<String> getRuleSet() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void setRuleSet(Set<String> set) {
		// TODO Auto-generated method stub
		
	}
	public String toString()
	{
		return name;
	}
}
